<?php

$oReq =& App::getRequest();
$oTpl =& App::getTemplate();
$oDb =& Database::get();

if ($oReq->get('go'))
{
	switch($oReq->get('type'))
	{
		case 'email':
			
			if ($sEmail = $oReq->get('email'))
			{			
				ob_clean();	
				App::loadClass('mail/Mailer');
				$oMail = new mail_Mailer();
				$mReturn = $oMail->send('email_blank', $sEmail, App::format('Mod_Admin.test_email'), array('FROM' => App::getParam('site_title'), 'CONTENT' => App::format('Mod_Admin.test_email')));
				$sContent = (is_array($mReturn) ? implode('<br />', $mReturn) : App::format('Mod_Admin.no_errors'));
				$sErrors = ob_get_contents();
				ob_clean();
			}
			
			break;
			
		case 'duplicate-friends':
			
			$aRows = $oDb->getRows("
				SELECT user, friend, count(friend) as cnt
				FROM ". App::getT('friends') ."
				GROUP BY user, friend
				HAVING cnt > 1
				ORDER BY cnt DESC
			");
			
			if (count($aRows))
			{
				$sCnt = '';
				foreach ($aRows as $aRow)
				{
					$sCnt .= '+' . $aRow['cnt'];
					$oDb->_delete(App::getT('friends'), "user = '". $aRow['user'] ."' AND friend = '". $aRow['friend'] ."' LIMIT ". ($aRow['cnt']-1) ."");
				}
				$sCnt = ltrim($sCnt, ',');
				eval('$iCnt = ('. $sCnt .');');
				$sContent = App::format('Mod_Admin.found_entries', $iCnt);
			}
			else 
			{
				$sContent = App::format('Mod_Admin.no_duplicate_entries');
			}
			
			break;
	}
	
	$oTpl->assign(array
	(
		'sContent' => (isset($sContent) ? $sContent : ''),
		'sErrors' => (isset($sErrors) ? $sErrors : '')
	));
}

?>